﻿using System.Web;
using HNAlbum.Logic.Entity;

namespace HNAlbum.Helper
{
    /// <summary>
    /// Manage across application session variables
    /// </summary>
    public class SessionManager
    {
        /// <summary>
        /// Enum to store session key names
        /// </summary>
        private enum SessionKey
        {
            IsAuthenticated,
            CurrentUser,
            DashboardPage,
        }

        #region Session sub classes declaration
        public UserSession User { get; set; }
        public PageSession Page { get; set; }
        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        public SessionManager()
        {
            //Initialise sub classes
            User = new UserSession();
            Page = new PageSession();
        }

        #region Session sub classes
        /// <summary>
        /// Class contains all user related session variables
        /// </summary>
        public class UserSession
        {
            public bool IsAuthenticated
            {
                set { HttpContext.Current.Session[SessionKey.IsAuthenticated.ToString()] = value; }
                get { return (HttpContext.Current.Session[SessionKey.IsAuthenticated.ToString()] != null) ? (bool)HttpContext.Current.Session[SessionKey.IsAuthenticated.ToString()] : false; }
            }
            public HNAlbumUser CurrentUser
            {
                set { HttpContext.Current.Session[SessionKey.CurrentUser.ToString()] = value; }
                get { return (HNAlbumUser)HttpContext.Current.Session[SessionKey.CurrentUser.ToString()]; }
            }
        }
        /// <summary>
        /// Contains all page related session variables
        /// </summary>
        public class PageSession
        {
            public int DashboardPage
            {
                set { HttpContext.Current.Session[SessionKey.DashboardPage.ToString()] = value; }
                get { return (HttpContext.Current.Session[SessionKey.DashboardPage.ToString()] != null) ? (int)HttpContext.Current.Session[SessionKey.DashboardPage.ToString()] : 1; }
            }
        }
        #endregion
    }
}
